<template>
    <el-dialog
            :title="title"
            :visible.sync="dialogVisible"
            width="30%"
            :before-close="handleClose">
        <div>
            <el-form
                    :rules="loginRules"
                    ref="form" :model="form" label-width="80px">

                <el-form-item label="id" prop="id" disabled="true">
                    <el-input v-model="form.id" :disabled="true"></el-input>
                </el-form-item>

                <el-form-item label="name" prop="name" disabled="false">
                    <el-input v-model="form.name" :disabled="false"></el-input>
                </el-form-item>

                <el-form-item label="uuidKey" prop="uuidKey" disabled="false">
                    <el-input v-model="form.uuidKey" :disabled="false"></el-input>
                </el-form-item>

                <el-form-item label="moduleName" prop="moduleName" disabled="false">
                    <el-input v-model="form.moduleName" :disabled="false"></el-input>
                </el-form-item>

                <el-form-item label="description" prop="description" disabled="false">
                    <el-input v-model="form.description" :disabled="false"></el-input>
                </el-form-item>

                <el-form-item label="fieldType" prop="fieldType" disabled="false">
<!--                    <el-input v-model="form.fieldType" :disabled="false"></el-input>-->
                    <el-select v-model="form.fieldType" :disabled="false">
                        <el-option :label="item.description" :value="item.id+''" v-for="item in fieldTypeList"></el-option>
                    </el-select>
                </el-form-item>


            </el-form>
        </div>
        <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="()=>{
   submit()
    }">确 定</el-button>
  </span>
    </el-dialog>

</template>
<script>

    export default {
        data() {
            return {
                title: "管理",
                dialogVisible: false,
                form: {id: "", name: "", uuidKey: "", moduleName: "", desc: "", fieldType: "",},
                loginRules: {
                    name: [{required: true, trigger: 'blur', message: "name不能为空"}],

                    uuidKey: [{required: true, trigger: 'blur', message: "uuidKey不能为空"}],

                    moduleName: [{required: true, trigger: 'blur', message: "moduleName不能为空"}],

                    description: [{required: false, trigger: 'blur', message: "desc不能为空"}],

                    fieldType: [{required: true, trigger: 'blur', message: "fieldType不能为空"}],

                },
                fieldTypeList:[],
            }
        },
        mounted(){
            this.ajaxFieldTypeList()
        },
        methods: {
            async ajaxFieldTypeList() {
                var _params = {}
                console.log("[get]  /moduleField/page")
                console.log('参数', JSON.stringify(_params))
                var result = await axios.get('/springboot6379/fieldType/listAll').then(res => res.data).then(res => res.result)
                console.log("fieldTypeList 结果", result)
                this.fieldTypeList = result
                this.fieldTypeListMap={}
                this.fieldTypeList.map((value)=>{
                    this.fieldTypeListMap[value.id]=value
                })

            },
            handleClose() {
                this.$data.dialogVisible = false;
            },
            init(_data) {
                if (_data && _data.id) {
                    this.title = "修改"
                } else {
                    this.title = "添加"
                }
                this.dialogVisible = true
                _data.fieldType=_data.fieldType+""
                this.form = _data ? _data : {}
            },
            async submit() {
                this.$refs['form'].validate(async (isyes) => {
                    if (isyes) {
                        var _params = this.form
                        console.log("[get]  /moduleField/add")
                        console.log('参数', JSON.stringify(_params))
                        var url = this.form.id ? '/springboot6379/moduleField/update' : '/springboot6379/moduleField/add'
                        var result = await axios.post(url, _params).then(res => res.data)
                        console.log("结果", result)
                        this.dialogVisible = false;
                        this.$emit('refresh')
                    }
                })
            }
        }
    }
</script>




